@extends('back.common.layout')
@section('title', '添加配置项')

@section('content')
    <div id="content">
        <div class="page-header">
            <div class="container-fluid">
                <div class="pull-right">
                    <button type="submit" form="form-brand" data-toggle="tooltip" title="保存" class="btn btn-primary"> <i class="fa fa-save"></i>
                    </button>
                    <a href="{{route('setting.list')}}" data-toggle="tooltip" title="取消" class="btn btn-default"> <i class="fa fa-reply"></i>
                    </a>
                </div>
                <h1>商品配置项</h1>
                <ul class="breadcrumb">
                    <li>
                        <a href="#">首页</a>
                    </li>
                    <li>
                        <a href="{{route('setting.set')}}">商品配置项</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="container-fluid">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        <i class="fa fa-pencil"></i>
                        设置商品配置项
                    </h3>
                </div>
                <div class="panel-body">
                    <!-- __ACTION__ -->
                    <form action="{{route('setting.set')}}" method="post" enctype="multipart/form-data" id="form-setting" class="form-horizontal">
                        {{ csrf_field() }}
                        @if (isset($setting->id))
                            <input type="hidden" name="id" id="input-setting_id" value="{{$setting->id}}">
                        @endif
                        <ul class="nav nav-tabs">
                            <li class="active">
                                <a href="#tab-general" data-toggle="tab">基本信息</a>
                            </li>
                        </ul>
                        <div class="tab-content">
                            <div class="tab-pane active" id="tab-general">

                                                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="input-key">程序key</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="key" value="{{isset($setting) ? $setting->key : ''}}" placeholder="程序key" id="input-key" class="form-control" />
                                        @if ($errors->has('key'))
                                            <label for="input-key" class="text-danger">{{$errors->first('key')}}</label>
                                        @endif
                                    </div>
                                </div>                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="input-value">配置值</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="value" value="{{isset($setting) ? $setting->value : ''}}" placeholder="配置值" id="input-value" class="form-control" />
                                        @if ($errors->has('value'))
                                            <label for="input-value" class="text-danger">{{$errors->first('value')}}</label>
                                        @endif
                                    </div>
                                </div>                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="input-title">配置标题</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="title" value="{{isset($setting) ? $setting->title : ''}}" placeholder="配置标题" id="input-title" class="form-control" />
                                        @if ($errors->has('title'))
                                            <label for="input-title" class="text-danger">{{$errors->first('title')}}</label>
                                        @endif
                                    </div>
                                </div>                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="input-setting_type_id">配置类型</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="setting_type_id" value="{{isset($setting) ? $setting->setting_type_id : ''}}" placeholder="配置类型" id="input-setting_type_id" class="form-control" />
                                        @if ($errors->has('setting_type_id'))
                                            <label for="input-setting_type_id" class="text-danger">{{$errors->first('setting_type_id')}}</label>
                                        @endif
                                    </div>
                                </div>                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="input-setting_group_id">配置分组</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="setting_group_id" value="{{isset($setting) ? $setting->setting_group_id : ''}}" placeholder="配置分组" id="input-setting_group_id" class="form-control" />
                                        @if ($errors->has('setting_group_id'))
                                            <label for="input-setting_group_id" class="text-danger">{{$errors->first('setting_group_id')}}</label>
                                        @endif
                                    </div>
                                </div>                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="input-sort_number">排序</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="sort_number" value="{{isset($setting) ? $setting->sort_number : ''}}" placeholder="排序" id="input-sort_number" class="form-control" />
                                        @if ($errors->has('sort_number'))
                                            <label for="input-sort_number" class="text-danger">{{$errors->first('sort_number')}}</label>
                                        @endif
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('appendJS')
    <script src="{{asset('/back/validate/jquery.validate.min.js')}}"></script>
    <script src="{{asset('/back/validate/additional-methods.min.js')}}"></script>
    <script src="{{asset('/back/validate/localization/messages_zh.min.js')}}"></script>

    <script>
        $(function() {
            $('#form-setting').validate({
                rules:{
                    title: {
                        required: true,
                        remote: {
                            url: '{{route('ajax.validator', ['name' => 'brand'])}}',
                            data: {
                                'id': $('#input-brand_id').size()==1 ? $('#input-brand_id').val() : 0
                            }
                        }
                    }
                },
                messages: {
                    title: {
                        required: '品牌不能为空',
                        remote: '品牌已经存在'
                    }
                },

                errorClass: 'text-danger',
                // 处理错误元素的位置
                // error, 错误信息元素
//                element, 出现错误的input元素
                errorPlacement: function(error, element) {
                    // 自己的行为, 设置has-error类
                    element.parents('div.form-group').addClass('has-error');

                    // 默认行为
                    error.appendTo(element.parent());
                },
                // 元素校验通过触发
                success: function (label, element) {
                    // 自己行为, 去掉has-error
                    $(element).parents('div.form-group').removeClass('has-error');
                    // 默认行为
                    label.empty().hide();
                }
            });
        });
    </script>
@endsection